<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String baseBath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <base href=<%=baseBath%>
          <%@include file="../common_css.jsp" %>

                  </head>
<body class="childrenBody">
<form class="layui-form" style="width:80%;">
    <input type="hidden" name="id" value="${cusOpportunity.id}">
    <input type="hidden" name="cusId" value="${cusOpportunity.cusId}">
    <input type="hidden" name="inputOpportunityState" value="${cusOpportunity.opportunityState}">
    <input type="hidden" name="inputCarId" value="${cusOpportunity.carId}">
    <div class="layui-form-item layui-row">
        <div class="layui-col-xs6">
            <label class="layui-form-label">客户名称</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input"
                       name="name" id="name" lay-verify="required" value="${cusOpportunity.customer.name}"
                       placeholder="请输入客户名"
                       <c:if test="${cusOpportunity.customer.name != null}">disabled</c:if>
                >
            </div>
        </div>
        <div class="layui-col-xs6">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input"
                       name="phone" id="phone" lay-verify="phone" value="${cusOpportunity.customer.phone}"
                       placeholder="请输入手机号"
                       <c:if test="${cusOpportunity.customer.name != null}">disabled</c:if>
                >
            </div>
        </div>
    </div>
    <div class="layui-form-item layui-row">
        <div class="layui-col-xs6">
            <label class="layui-form-label">购车可能性</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input"
                       name="probably" id="probably" lay-verify="required" value="${cusOpportunity.probably}"
                       placeholder="请输入购车可能性">
            </div>
        </div>

        <div class="layui-col-xs6">
            <label class="layui-form-label">商机状态</label>
            <div class="layui-input-block">
                <select name="opportunityState" id="opportunityState" disabled>
                </select>
            </div>
        </div>
    </div>


    <div class="layui-form-item layui-row">
        <div class="layui-col-xs8">
            <label class="layui-form-label">意向车辆</label>
            <div class="layui-input-block">
                <select name="carId"  id="carId">
                    <option value="" >请选择</option>
                </select>
            </div>
        </div>
    </div>

    <div class="layui-form-item layui-row">
        <div class="layui-form-item layui-row layui-col-xs12">
            <label class="layui-form-label">客户描述</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入对客户的描述" name="describe"
                          class="layui-textarea">${cusOpportunity.describe}</textarea>
            </div>
        </div>
        <div class="layui-form-item layui-row layui-col-xs12">
            <label class="layui-form-label">失败原因</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入失败原因" name="failReason" class="layui-textarea">${cusOpportunity.failReason}</textarea>
            </div>
        </div>
    </div>

    <br/>
    <div class="layui-form-item layui-row layui-col-xs12">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-lg" lay-submit=""
                    lay-filter="updateCusOpportunity">确认
            </button>
            <button class="layui-btn layui-btn-lg layui-btn-normal">取消</button>
        </div>
    </div>
</form>

<script type="text/javascript">
    layui.use(['form', 'layer'], function () {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery;
        $.post("/dictionaries/findOpportunityState", function (res) {
            //console.log(res)
            for (var i = 0; i < res.length; i++) {
                //绑定下拉框显示
                if ($("input[name='inputOpportunityState']").val() == res[i].valueId) {
                    $("#opportunityState").append("<option value=\"" + res[i].valueId + "\"  selected='selected' >" + res[i].valueName + "</option>");
                } else {
                    $("#opportunityState").append("<option value=\"" + res[i].valueId + "\"   >" + res[i].valueName + "</option>");
                }

            }
            // 重新渲染下拉框内容
            layui.form.render("select");
        });
        $.post("/car/findCarAll",function (res) {
            for(var i=0;i<res.length;i++){
                if($("input[name='inputCarId']").val() == res[i].id){
                    $("#carId").append("<option value=\""+res[i].id+"\" selected  >"+res[i].series+" "+res[i].model+"</option>");
                }else{
                    $("#carId").append("<option value=\""+res[i].id+"\"   >"+res[i].series+" "+res[i].model+"</option>");
                }
            }
            layui.form.render("select");
        });

        form.on('submit(updateCusOpportunity)', function (data) {
            var index = top.layer.msg("数据提交中,请稍后...", {icon: 16, time: false, shade: 0.8});

            var url = "/cusOpportunity/updateCusOpportunity";
            $.post(url, data.field, function (res) {
                if (res == 'success') {
                    top.layer.msg("操作成功");
                    top.layer.close(index);
                    layer.closeAll("iframe");
                    // 刷新父页面
                    parent.location.reload();
                }
            });
            return false;
        });
        // $.post("/dictionaries/findDriveInterest", function (res) {
        //     //console.log(res)
        //     for (var i = 0; i < res.length; i++) {
        //         //绑定下拉框显示
        //         if ($("input[name='InputDriveInterest']").val() == res[i].valueId) {
        //             $("#driveInterest").append("<option value=\"" + res[i].valueId + "\"  selected='selected' >" + res[i].valueName + "</option>");
        //         } else {
        //             $("#driveInterest").append("<option value=\"" + res[i].valueId + "\"   >" + res[i].valueName + "</option>");
        //         }
        //
        //     }
        //     // 重新渲染下拉框内容
        //     layui.form.render("select");
        // });
        // $.post("/user/findUser", function (res) {
        //     //console.log(res)
        //     for (var i = 0; i < res.length; i++) {
        //         //绑定下拉框显示
        //         if ($("input[name='InputUserId']").val() == res[i].id) {
        //             $("#userId").append("<option value=\"" + res[i].id + "\"  selected='selected' >" + res[i].name + "</option>");
        //         } else {
        //             $("#userId").append("<option value=\"" + res[i].id + "\"   >" + res[i].name + "</option>");
        //         }
        //     }
        //     // 重新渲染下拉框内容
        //     layui.form.render("select");
        // });
        // $.post("/activity/findActivity", function (res) {
        //     //console.log(res)
        //     for (var i = 0; i < res.length; i++) {
        //         //绑定下拉框显示
        //         if ($("input[name='InputSource']").val() == res[i].id) {
        //             $("#source").append("<option value=\"" + res[i].id + "\"  selected='selected' >" + res[i].name + "</option>");
        //         } else {
        //             $("#source").append("<option value=\"" + res[i].id + "\"   >" + res[i].name + "</option>");
        //         }
        //     }
        //     // 重新渲染下拉框内容
        //     layui.form.render("select");
        // });
        // $.post("/dictionaries/findIntentionLevel", function (res) {
        //     //console.log(res)
        //     for (var i = 0; i < res.length; i++) {
        //         //绑定下拉框显示
        //         if ($("input[name='InputIntentionLevel']").val() == res[i].valueId) {
        //             $("#intentionLevel").append("<option value=\"" + res[i].valueId + "\"  selected='selected' >" + res[i].valueName + "</option>");
        //         } else {
        //             $("#intentionLevel").append("<option value=\"" + res[i].valueId + "\"   >" + res[i].valueName + "</option>");
        //         }
        //     }
        //     // 重新渲染下拉框内容
        //     layui.form.render("select");
        // });



    });
</script>
</body>
</html>